//C++标准头文件
#include <iostream>
// G4提供的头文件
#include "G4RunManager.hh"
#include "QGSP_BERT_HP.hh"

#include "G4UImanager.hh"
#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"
#include "G4MTRunManager.hh"

// 用户编写的头文件
#include "G4StartDetectorConstruction.hh"
#include "G4StartPrimaryGeneratorAction.hh"

int main(int argc,char** argv){         // main函数
    
    G4UIExecutive* ui = nullptr;

    if(argc == 1)
        ui = new G4UIExecutive(argc,argv);

        
    // 创建G4运行对象
    G4RunManager * runManager = new G4RunManager;

    // G4运行对象的参数配置    
    // 物理模型配置
    runManager->SetUserInitialization(new G4StartDetectorConstruction);
    // 物理过程描述
    runManager->SetUserInitialization(new QGSP_BERT_HP);
    // 初级事件的配置
    runManager->SetUserAction(new G4StartPrimaryGeneratorAction);

    // 运行可视化增加的代码
    auto visManager = new G4VisExecutive;
    visManager->Initialize();

    auto UImanager = G4UImanager::GetUIpointer();
    if (!ui) {
        G4String command = "/control/execute ";
        G4String fileName = argv[1];
        UImanager->ApplyCommand(command + fileName);
    } else {
        UImanager->ApplyCommand("/control/execute vis.mac");
        ui->SessionStart();
        delete ui;
    }



    // // G4内核初始化
    // runManager->Initialize();

    // // 打出3个粒子
    // runManager->BeamOn(100);

    // // 释放内存
    // delete runManager;

    // std::cout << "程序运行结束";

    return 0;

}